function [fname, fpath] = uigetimage(titl)
%[filename, fpath] = UIGETIMAGE(titl)  
% Use of UIGETFILE tailored for selection of image file(s) with formats
% supported by IMREAD. A dialog box is displayed for the user to fill in,
% and returns the filename and path strings.
%
% You can choose a single file, or several using the Shift and Ctrl keys
% in the usual way supported by the operating system.
%
% titl  = [optional] title or request, e.g., 'Please select first image'
% fname = file name, char variable for single file, or
%         cell array of file names if several are chosen.
% fpath = [optional] file path (directory of folder) for chosen file(s)
%         if fpath is not asked for, then fname contains the full path
%         for each file chosen.
%
% NEEDS: UIGETFILE
%
% Example usage:
%  Returns full file path to selected file(s)
%>  fn = uigetimage('Pick a picture file')
%
% Returns names and path for file(s) selcted with default title
%>  [fn, fpath] = uigetimage;
%
% Peter D. Burns, pdburns@ieee.org 5 Nov. 2015

if nargin<1;
    titl = 'Select input image file (tif, jpg, bmp, gif, png... )';
end

  sup =['*tif;*TIF;*.tiff;*.TIFF;*.jpg;*.jpeg;*.JPG;*.JPEG;', ...
       '*.tif;*.TIF;*.tiff;*.TIFF;*.gif;*.GIF;*.bmp;*.BMP;*.png;*PNG'];  
  ftype =  {sup,  'Supported: jpg, tif, bmp, gif, png ...'; ...     
           '*.jpg;*.jpeg;*.JPG;*.JPEG',  'JPEG'; ...
           '*.tif;*.TIF;*.tiff;*.TIFF',  'TIF'; ... 
           '*.gif;*.GIF;',               'GIF'; ...
           '*.bmp;*.BMP;',               'BMP'; ...
           '*.png;*.PNG;',               'PNG'; ...
           '*.*',                        'All Files (*.*)'};
       
    [fname, fpath] = uigetfile(ftype, titl, 'MultiSelect', 'on');
 %  To restrict selection to a single file, uncomment the next line, and
 %  delete the previous one above
 %  [fname, fpath] = uigetfile(ftype, titl);
 
    fclass = class(fname);
    if strcmp(fclass,'double')==1;    
        disp('No file chosen');
        return      
  % If output argument, fpath, is not asked for, fname contains full path
    elseif nargout<2
        if iscell(fname) ~=1;
            fname = [fpath,fname];
        else for ii=1:length(fname)
                fname{ii}= [fpath,fname{ii}];
            end
        end
    end
